/*
 * 9.7_1.cpp
 *
 *  Created on: 2012-5-21
 *      Author: jawinton
 */

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define MAX_COUNT 92

int queenPlace[MAX_COUNT][8], mark[8];
int count = 0;
int board[8][8];

void putQueen (int ithQueen) {
	if (ithQueen == 8) {
		for (int i=0; i<8; i++)
			queenPlace[count][i] = mark[i];
		count++;
		return;
	}
	for (int i=0; i<8; i++) {
		if (board[i][ithQueen] == -1) {
			board[i][ithQueen] = ithQueen;
			//for (int k=count; k<MAX_COUNT; k++)
			//	queenPlace[k][ithQueen] = i+1;
			mark[ithQueen] = i+1;
			for (int j=0; j<8; j++) {
				for (int k=0; k<8; k++) {
					if (board[j][k] == -1 && (k==ithQueen || j==i || (abs(j-i) == abs(k-ithQueen)))) {
						board[j][k] = ithQueen;
					}
				}
			}
			putQueen(ithQueen+1);
			for (int j=0; j<8; j++) {
				for (int k=0; k<8; k++) {
					if (board[j][k] == ithQueen) board[j][k] = -1;
				}
			}
		}
	}
}

int main (void) {
	int n;
	for (int i=0; i<8; i++) {
		for (int j=0; j<8; j++) {
			board[i][j]= -1;
		}
		for (int j=0; j<MAX_COUNT; j++) {
			queenPlace[j][i] = 0;
		}
	}
	putQueen(0);
	scanf("%d", &n);
	for (int i=0; i<n; i++) {
		int ith;
		scanf("%d", &ith);
		for (int j=0; j<8; j++)
			printf("%d", queenPlace[ith-1][j]);
		printf("\n");
	}
	return 0;
}
